-
Notifications
You must be signed in to change notification settings - Fork 887
rework complex enum field conversion #4694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Agreed this could use a refactor, probably that's easier after we remove ToPyObject
and other backwards-compatibility arms from the #[pyo3(get)]
code.
Hello, Thanks for this implementation. Just two questions:
I'm trying to mimic the behavior in Python and in Rust of an Expression builder, and as these can become complex, it makes sense in my use-case to have them be clonable and enable equality checks. Thanks Edit: My use case currently requires me to define the enum as follows. Would it be possible for PyO3 to automatically convert the #[derive(Debug)]
#[cfg_attr(not(feature = "python"), Clone, PartialEq)]
pub enum VectorExpr {
Fixed {
x: f64,
y: f64,
z: f64,
}, // Unitless vector, for arbitrary computations
Radius(StateSpec),
Velocity(StateSpec),
OrbitalMomentum(StateSpec),
EccentricityVector(StateSpec),
#[cfg(not(feature = "python"))]
CrossProduct {
a: Box<Self>,
b: Box<Self>,
},
#[cfg(feature = "python")]
CrossProduct {
a: Py<VectorExpr>,
b: Py<VectorExpr>,
},
} |
It can't be For similar reasons As for |
Understood, thanks for the details. Do you have any recommendations on how I should approach this enum I'm working on? |
This reworks the complex enum field conversion to use
IntoPyObject
either by reference if available, or together withClone
if not.I think in the future we should probably rework complex enums to make them use of the same infrastructure we already have for
#[pyo3(get)]
.Closes #4216
Xref #4651